package com.qxbb.report.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qxbb.report.bo.ImgBo;
import com.qxbb.report.bo.ProductHistoryBO;
import com.qxbb.report.dao.ChainUserInforMapper;
import com.qxbb.report.dao.ProductMapper;
import com.qxbb.report.pojo.ChainUserInfor;
import com.qxbb.report.pojo.Product;
import com.qxbb.report.service.ProductService;
import com.qxbb.report.utils.StringUtils;
import com.qxbb.report.utils.ZipImgUtils;
import com.qxbb.report.utils.http.HttpResult;
import com.qxbb.report.vo.ImgVO;
import com.qxbb.report.vo.ProductHistoryVO;
import com.qxbb.report.vo.ProductListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @version 1.0
 * @author: pebble
 * @data 2023/10/10 16:08
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {


    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private ChainUserInforMapper userInforMapper;

    @Autowired
    private ZipImgUtils zipImgUtils = new ZipImgUtils();

    /**
     * 获取产品颜色
     *
     * @param productId
     * @return
     */
    @Override
    public String slectColorByProductId(Integer productId) {
        return productMapper.selectColorByProductId(productId);
    }

    /**
     * 查询品牌名称
     *
     * @param categoryId
     * @return
     */
    @Override
    public String selectBrandNameByProductCode(Integer categoryId) {
        return productMapper.selectBrandNameProductCode(categoryId);
    }

    @Override
    public String selectBrandName(Integer brandId) {
        return productMapper.selectBrandName(brandId);
    }

    @Override
    public List<ImgVO> selectImgByLike(ImgBo imgBo) throws IOException {
        List<ImgVO> imgVOS = productMapper.selectImgByLike(imgBo);
        for (ImgVO imgVO : imgVOS) {
            imgVO.setImgPath(zipImgUtils.getPicPath(imgVO.getBarCode()));
        }
        return imgVOS;
    }

    @Override
    public String getImgNetworkURL(String barcode) {
        return zipImgUtils.getPicPath(barcode);
    }

    @Override
    public List<ProductListVO> selectLikeProduct(String productCode,Integer chainUserId) {
        ChainUserInfor userInfor = new ChainUserInfor();
        if (chainUserId != 0){
             userInfor = userInforMapper.selectByUserId(chainUserId);
        }
        return productMapper.selectListProduct(productCode,userInfor.getChainId());
    }


}
